<html lang="en">
<head>
    <title>游记推荐管理</title>
    <#include "../common/header.ftl">
    <script type="text/javascript" src="/js/plugins/jquery-form/jquery.form.js"></script>
    <script>
        $(function () {
            $(".editCommendBtn").click(function () {
                //重置表单
                $("#editForm")[0].reset();
                var json = $(this).data("json");
                $("#editForm input[name='title']").val(json.title)
                $("#editForm input[name='subTitle']").val(json.subTitle)
                $("#editForm input[name='schedule']").val(json.schedule)
                $("#editForm input[name='coverUrl']").val(json.coverUrl)
                $("#coverUrl").attr("src",json.coverUrl);
                $("#editForm select[name='type']").val(json.type)
                $("#editForm input[name='id']").val(json.id)
                $("#editForm input[name='travel.id']").val(json.travelId);
                //动态拼接url
                var href = $('#skip').data("href");
                $("#skip").attr("href",href+json.travelId);
                $("#editModal").modal("show");
            })
            //修改操作
            $(".saveBtn").click(function () {
                //提交表单之前判断是否选中推荐的类型,如果不等于-1,在提交表单,否则不提交表单
                $('#editForm').ajaxSubmit({
                    beforeSubmit:function (params) {
                        var type = $("#editForm select[name='type']");
                        if (type.val()==-1) {
                            $.messager.alert("温馨提示","请选择推荐的类型")
                            return false;
                        }
                        },
                    success:function (data) {
                        if(data.success){
                            window.location.reload();
                        }else {
                            $.messager.alert("温馨提示",e.msg);
                        }
                    }
                })
            })
            //推荐取消
            $(".cancelBtn").click(function () {
                $.messager.confirm("温馨提示","确定要取消推荐吗?",function () {
                    var json = $('.cancelBtn').data("json");
                    $.get("/travelCommend/cancel.do",{id:json.id,travelId:json.travelId},function (data) {
                        if (data.success) {
                            window.location.reload();
                        }else {
                            $.messager.alert("温馨提示",data.meg);
                        }
                    })
                })
            });
            //图片覆盖
            $("#editForm input[name='file']").change(function () {
                console.log(1);
                var url = window.URL.createObjectURL(this.files[0]);
                $('#coverUrl').attr("src",url);
            })
        })

    </script>
</head>
<body>
<!--左侧菜单回显变量设置-->
<#assign currentMenu="travelCommend">
<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-2">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-10">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">游记推荐管理</h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/travelCommend/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label for="keyword">关键字:</label>
                    <input type="text" class="form-control" id="keyword" name="keyword" value="${qo.keyword!}" placeholder="请输入标题">
                </div>
                <div class="form-group">
                    <div class="col-sm-6">
                        <select  name="type" class="form-control selectType">
                            <option value="-1">--请选择--</option>
                            <option value="0">每周推荐</option>
                            <option value="1">每月推荐</option>
                            <option value="2">攻略推荐</option>
                        </select>
                    </div>
                    <script>
                        $(".selectType").val(${qo.type})
                    </script>
                </div>
                <button id="btn_query" class="btn btn-info"><span class="glyphicon glyphicon-search"></span> 查询</button>

            </form>
            <table class="table table-striped table-hover">
                <thead>
                <tr>
                    <th>封面</th>
                    <th>标题</th>
                    <th>副标题</th>
                    <th>推荐时间安排</th>
                    <th>推荐类型</th>
                    <th>编辑</th>
                </tr>
                </thead>
               <#list result.list as entity >
                     <tr>
                         <td><img src="${entity.coverUrl!}" width="30px;"></td>
                         <td>${(entity.title)!}</td>
                         <td>${(entity.subTitle)!}</td>
                         <td>${(entity.schedule?string("yyyy-MM-dd"))!}</td>
                         <td>${entity.typeDisplay!}</td>
                         <td>
                             <a href="javascript:;" class="btn editCommendBtn" data-json='${entity.jsonString!}' >修改</a>
                             <a href="javascript:;" class="btn cancelBtn"  data-json='${entity.jsonString!}'>推荐取消</a>
                         </td>
                     </tr>
                </#list>
            </table>
            <#include "../common/page.ftl">
        </div>
    </div>
</div>

<#--推荐游记编辑模态框-->
<div class="modal fade" id="editModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span> </button>
                <h4 class="modal-title">推荐游记编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/travelCommend/saveOrUpdate.do" method="post" enctype="multipart/form-data" id="editForm">
                    <input type="hidden" name="id">
                    <input type="hidden" name="travel.id">
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="title" value="" placeholder="请输入标题名称">
                        </div>
                    </div>
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">副标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="subTitle" value="" placeholder="请输入副标题名称">
                        </div>
                    </div>
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">封面：</label>
                        <div class="col-sm-6">
                            <img id="coverUrl" width="200px;">

                            <input type="file" id="fileId" name="file">
                            <#--如果上面的file没有选中,会为空值,updata时,还会 更新,
                                解决
                            -->
                            <input type="hidden" name="coverUrl">
                        </div>
                    </div>
                    <div class="form-group">
                        <label  class="col-sm-3 control-label">推荐时间：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" readonly name="schedule" value="" onclick="WdatePicker()">
                        </div>
                    </div>
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">推荐类型：</label>
                        <div class="col-sm-6">
                            <select name="type" class="form-control">
                                <option value="-1">--请选择--</option>
                                <option value="0">每周推荐</option>
                                <option value="1">每月推荐</option>
                                <option value="2">攻略推荐</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group" style="text-align: center">
                        <a href="javascript:void(0)" target="_blank" data-href="/travel/releaseList.do?travelId=" id="skip">点击查看游记文章明细</a>
                    </div>
                </form>
            </div>

            <div class="modal-footer">
                <button type="submit" class="btn btn-primary saveBtn" >保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal" >取消</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>
